﻿using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using FantomNext.Controls;

namespace FantomNext.Views;

public partial class SceneEditor : UserControl
{
    public SceneEditor()
    {
        InitializeComponent();
        //AddHandler(UserControl.PointerPressedEvent, OnPointerPressed2, Avalonia.Interactivity.RoutingStrategies.Tunnel);
    }

    protected override void OnLoaded(RoutedEventArgs e)
    {
        base.OnLoaded(e);
        PART_Panel.PointerPressed += PART_Panel_PointerPressed;
    }

    private void PART_Panel_PointerPressed(object? sender, PointerPressedEventArgs e)
    {
        if (e.Source == sender)
        {
            GlobalData.ScenePresenter.ClearSelection();
        }
        else if (e.Source is FantomShape fantomShape)
        {
            GlobalData.ScenePresenter.ClearSelection();
            GlobalData.ScenePresenter.SetSelection([fantomShape.Id]);
        }
        else
        {
            // TODO NOTHING
        }

    }

    private void PART_FantomCanvas_PointerPressed(object? sender, PointerPressedEventArgs e)
    {
        e.Handled = true;
    }
}